﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Model;
using System.Data;
using BLL;
using Maticsoft.BLL;

public partial class PersonInfo_InventoryEdit : BasePage
{
    private Access access = new Access();
    GiftBO gbo = new GiftBO();
    InventoryBO ibo = new InventoryBO();
    private static int id;
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!this.IsPostBack)
        {

            if (GetQeuryString("para") == "update")
            {
                string id = GetQeuryString("id");
                Gift g = gbo.GetModel(int.Parse(id));
                InitData(g);
            }
            else if (GetQeuryString("para") == "add")
            {
                string id = GetQeuryString("id");
                Gift g = gbo.GetModel(int.Parse(id));
                InitData(g);
            }
        }
    }
    protected void Button1_Click(object sender, EventArgs e)
    {
  
            
                if (GetQeuryString("para") == "add")
                {
                   Inventory i=new Inventory();
                    i.GID=Convert.ToInt32(GetQeuryString("id"));
                    i.Num=int.Parse(txtIntegral.Text);
                    i.Time=DateTime.Parse(txtTime.Text);
                    ibo.Add(i);
                    Gift g = gbo.GetModel(int.Parse(i.GID.ToString()));
                    g.Sum += i.Num;
                    g.Surplus += i.Num;
                    gbo.Update(g);
                    AlertAndCloseAndReloadParendDataGrid("保存成功！", "grid");
                    //}
                }
            
       
    }

    #region 私有方法
    private SalesRecord GetEntity()
    {
        try
        {


            SalesRecord sa = new SalesRecord();
            //sa.Amount = decimal.Parse(txtAmount.Text);
            //sa.CreateDate = DateTime.Now;
            //sa.Integral = int.Parse(txtIntegral.Text);
            //sa.Number = int.Parse(txtNumber.Text);
            //sa.PersonNo = ddlPersonNo.SelectedValue;
            //sa.Product = txtProduct.Text;
            //sa.Time = DateTime.Parse(txtTime.Text);
            return sa;
        }
        catch (Exception)
        {
            return null;
        }
    }
    private void InitData(Gift g)
    {
        lblBroken.Text = g.Broken.ToString();
        lblName.Text = g.Name;
        lblS.Text = g.Surplus.ToString();
        lblZong.Text = g.Sum.ToString();
        lblGiftNo.Text = g.GiftNo;
    }

    #endregion
}